package com.gzu.emr.service.impl;

import com.gzu.emr.dto.Prescription;
import com.gzu.emr.mapper.PrescriptionMapper;
import com.gzu.emr.service.PrescriptionService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author chuchu
 * @version 1.0
 * @date 2023-07-20
 **/
@Service
public class PrescriptionServiceImpl implements PrescriptionService {


    @Resource
    PrescriptionMapper prescriptionMapper;


    @Override
    public Integer savePrescription(Prescription prescription) {

        int row = prescriptionMapper.insertPrescription(prescription);
        if(row != 1) {
            //throw todo
        }

        return row;
    }

    @Override
    public Integer savePrescriptionAndDrugs(Integer preId, List<Integer> listId, List<Integer> listCount) {
        int row = 0;    //受影响行数
        for(int i = 0; i < listId.size(); ++i) {
            System.err.println("insert " + preId + listId.get(i) + listCount.get(i));
            row += prescriptionMapper.insertPrescriptionAndDrugs(preId, listId.get(i), listCount.get(i));
        }

        if(row != listId.size()) {
            //exception
            return 0;
        }
        return row;
    }
}
